/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cp3120.model.pricing;

import cp3120.model.*;
import java.util.List;

/**
 *
 * @author jc154639
 */
public class DiscountNthTicket extends PricingStrategy {
    public DiscountNthTicket() {
        setVar("interval", "1");
        setVar("discountRate", "0");
    }

    private int getInterval() {
        return Integer.valueOf(getVar("interval"));
    }

    private float getDiscountRate() {
        return Float.valueOf(getVar("discountRate"));
    }

    public void execute(Purchase purchase) {
        List<Ticket> tickets = purchase.getTickets();

        for (int i = getInterval() - 1; i < tickets.size(); i += getInterval()) {
            Ticket ticket = tickets.get(i);
            ticket.setPrice(ticket.getPrice() - (ticket.getPrice() * getDiscountRate()));
        }
    }

    public static void main(String[] args) {
        new DiscountNthTicket();
    }
}
